function getCookie(name) {
    var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
    return r ? r[1] : undefined;
}

$(function () {
    $("#pay").click(function(){
        alert("1234234")
    })
    $("#pay").submit(function (e) {
        // 阻止表单的默认提交行为
        e.preventDefault();
        var price = $('.price').val();
        var fangshi = $('.fangshi').val();

        // 组织参数
        var params = {
            "price": price,
            "fangshi": fangshi
        };

        // TODO: 请求修改用户密码
        $.ajax({
            url: "/user/pay_info",
            type: "post",
            data: JSON.stringify(params),
            contentType: "application/json",
            headers: {
                "X-CSRFToken": getCookie("csrf_token")
            },
            success: function (resp) {
                if (resp.errno == "0") {
                    // `充值`成功
                    alert(resp.errmsg)
//                    setTimeout(function () {
//            		    window.location.href = "/login"
//					}, "1000");
                }
                else {
                    // `充值`失败
                    alert(resp.errmsg)
                }
            }
        })

    })
});